package com.example.jsruntimedemo.js.view;

import com.example.jsruntimedemo.js.dom.DomButton;
import com.example.jsruntimedemo.js.dom.DomElement;
import com.example.jsruntimedemo.js.dom.DomText;
import com.example.jsruntimedemo.js.dom.DomVerticalLayout;

public class JsViewFactory {
    public static JsView create(DomElement domElement) {
        if (domElement == null) {
            return null;
        }
        String type = domElement.type;
        switch (type) {
            case "text":
                TextJsView textJsView = new TextJsView();
                textJsView.mDomElement = (DomText) domElement;
                return textJsView;
            case "button":
                ButtonJsView buttonJsView = new ButtonJsView();
                buttonJsView.mDomElement = (DomButton) domElement;
                return buttonJsView;
            case "verticalLayout":
                VerticalLayoutJsView verticalLayoutJsView = new VerticalLayoutJsView();
                verticalLayoutJsView.mDomElement = (DomVerticalLayout) domElement;
                return verticalLayoutJsView;
        }
        return null;
    }
}
